package myzd.api.controllers;
import io.swagger.annotations.*;
import libedge.annotations.Authentication;
import libedge.domain.exceptions.GenericException;
import libedge.domain.request.ResultWrapper;
import lombok.extern.slf4j.Slf4j;
import myzd.api.domain.PagedResult;
import myzd.domain.response.City;
import myzd.domain.response.Counties;
import myzd.domain.response.Province;
import myzd.domain.response.Provinces;
import myzd.services.DoctorKbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author zks
 * @since 2017/10/18 18:31
 */
@RestController
@Slf4j
@Api(description = "省市区县相关接口")
public class CityController {
  @Autowired
  private DoctorKbService doctorKbService;

  @GetMapping("api/v1/cities")
  @ApiOperation(value = "获取城市列表", notes = "获取城市列表 1.is_capital_order 1-按照省会城市靠前排序", produces = "application/json")
  @Authentication
  @ApiImplicitParams({
    @ApiImplicitParam(name = "Authorization", value = "Session Id", required = true, dataType = "string", paramType = "header")
  })
  public ResultWrapper<PagedResult<City>> searchCities(
    @ApiParam("省份ID") @RequestParam(value = "province_id", required = false) Integer provinceId,
    @ApiParam("城市名称") @RequestParam(value = "city_name", required = false) String cityName,
    @ApiParam("省会城市排序在前 1：按省会城市排序") @RequestParam(value = "is_capital_order", required = false) Integer isCapitalOrder
  ) throws GenericException {
    return new ResultWrapper<>(doctorKbService.searchCity(provinceId, cityName, isCapitalOrder));
  }

  @GetMapping("api/v1/counties")
  @ApiOperation(value = "获取城市下面县", produces = "application/json")
  @Authentication
  @ApiImplicitParams({
    @ApiImplicitParam(name = "Authorization", value = "Session Id", required = true, dataType = "string", paramType = "header")
  })
  public ResultWrapper<PagedResult<Counties>> searchCounties(
    @ApiParam(value = "城市ID", required = true) @RequestParam(value = "id") Integer cityId
  ) throws GenericException {
    return new ResultWrapper<>(doctorKbService.searchCounties(cityId));
  }

  @GetMapping("api/v1/provinces")
  @ApiOperation(value = "获取省份列表", produces = "application/json")
  @Authentication
  @ApiImplicitParams({
    @ApiImplicitParam(name = "Authorization", value = "Session Id", required = true, dataType = "string", paramType = "header")
  })
  public ResultWrapper<PagedResult<Province>> searchProvince(@ApiParam("拼音字段") @RequestParam(value = "initial", required = false) String initial) throws GenericException {
    return new ResultWrapper<>(doctorKbService.searchProvinceList(initial));
  }

  @GetMapping("api/v2/provinces")
  @Authentication
  @ApiImplicitParams({
    @ApiImplicitParam(name = "Authorization", value = "Session Id", required = true, dataType = "string", paramType = "header")
  })
  @ApiOperation(value = "获取所有省份的列表（不包含该省的下级市）", produces = "application/json")
  public ResultWrapper<PagedResult<Provinces>> searchProvinceByDesignatedCity(@ApiParam("拼音字段") @RequestParam(value = "initial", required = false) String initial) throws GenericException {
    return new ResultWrapper<>(doctorKbService.searchProvinceListByDesignatedCity(initial));
  }

}
